package org.gamma.example.applet;

import netscape.javascript.JSObject;
import org.gamma.applet.GammaTask;

public class TestTask extends GammaTask {
	@Override
	protected void respond(JSObject input, JSObject output) {
		Object obj = input.getMember("number");
		int number = -1;
		
		if(obj instanceof Integer) {
			number = (Integer)obj;
		}
		else {
			number = Integer.parseInt(obj.toString());
		}
		
		TestApplet applet = (TestApplet)getApplet();
		applet.log("(Applet thread) Generating response for request " + number + " to be returned via message slot " + getIndex() + '.');
		
        int wait = (10 - (number % 10)) * 1000;
        try {
			Thread.sleep(wait);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
        output.setMember("response", "...applet thread waited " + wait + " milliseconds to respond to request " + number + '.');
	}
}
